package service;

import dao.UserDao;
import entity.User;

import java.sql.SQLException;
import java.util.Scanner;

public class UserService {
    private Scanner scanner;

    public UserService() {
        UserDao UserDao = new UserDao();
    }

   public boolean addUser(User user) throws SQLException {
       if (!UserDao.existsUsername(user.getName())){
           UserDao.addUser(user);
           return true;
       }else {
           return false;
       }

   }
   public boolean deleteUser(String username ) throws SQLException {
        if (UserDao.existsUsername(username)){
            UserDao.deleteUser(username);
            return true;
        }
        System.out.println("用户不存在");
        return false;
   }
   public static boolean revise(User user) throws SQLException {
       if (UserDao.existsUsername(user.getName())) {
           UserDao.reviseUser(user);
           return true;
       }
       System.out.println("用户不存在");
       return false;
   }

   public static int allUser() {
        UserDao.inquireAll();
        return 0;
   }
   public static boolean inquiryUser(String name) throws SQLException {
      if (UserDao.existsUsername(name)) {
      UserDao.inquiry(name);
      return true;
      }
      System.out.println("用户不存在");
      return false;

   }
}


